<template>
	<view class="wrap">
		<!-- <view class="search">
			<u-search v-model="keywords" @custom="search" @search="search"></u-search>
		</view> -->
		<u-form class="form" :model="query" ref="uForm" label-position="left">
			<u-form-item label="任务年度" label-width="180">
				<js-select
					v-model="query.taskYear"
					:items="yearList"
					placeholder="请选择任务年度"
					
					@confirm="getYear1(arguments)"
					:label-value="query.taskYearName"
					@label-input="query.taskYear = $event"
				></js-select>
			</u-form-item>
		
			<u-form-item label="任务状态" label-width="180">
				<js-select
					v-model="query.remarks"
					:items="statusSelectList"
					placeholder="请选择任务类型"
					@confirm="getStatusType(arguments)"
					:label-value="query.taskStatusName"
					@label-input="query.taskStatusCode = $event"
				></js-select>
			</u-form-item>
			<u-form-item label="关键字" label-width="180"><u-input placeholder="请输入关键字" v-model="query.taskTitle" type="text" maxlength="200"></u-input></u-form-item>
		</u-form>
		<view class="uni-flex" style="-webkit-justify-content: flex-end;justify-content: flex-end;margin-bottom: 10rpx;">
			<u-button type="primary" style="margin-top: 25rpx; width: 30%; margin-bottom: 4rpx" @click="doQuery" :plain="true" :hairline="true" text="查询">查询</u-button>
			<u-button type="primary" style="margin-top: 25rpx; width: 30%; margin-bottom: 4rpx" @click="resetAll" :plain="true" :hairline="true" text="重置">重置</u-button>
		</view>
		<scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore">
			<u-cell-group class="list" :border="false">
				<u-swipe-action v-for="(item, index) in list" :key="item.id" :index="index" @click="optionsClick">
					<u-cell-item :arrow="true" @click="navTo('taskReceiveForm?id='+item.id)"style="border-bottom: 1px solid #ededed">
						<text slot="title">{{item.taskTitle || item.id}}</text>
						<view slot="label" style="padding-bottom:20rpx">牵头责任单位：{{item.leaderOrgName}}</view>
						<view slot="label" style="padding-bottom:20rpx">任务内容：{{item.taskContent}}</view>
					</u-cell-item>
				</u-swipe-action>
			</u-cell-group>
			<view class="loadmore" @click="loadMore">
				<u-loadmore :status="loadStatus"></u-loadmore>
			</view>
		</scroll-view>
		<!-- <view class="btn-plus" @click="navTo('taskReceiveForm')">
			<u-icon name="plus-circle-fill" size="90" color="#3d87ff"></u-icon>
		</view> -->
	</view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
export default {
	data() {
		return {
			keywords: '',
			query: {
				pageNo: 1,
				pageSize: 20,
				remarks:1,
				taskStatus:1,
				taskYear: '',
				taskYearName: '',
				transferFlag:''
			},
			statusSelectList:[
				{name:'待接收',value:1},
				{name:'进行中',value:2},
				{name:'已完成',value:3},
				{name:'已转办',value:4},
			],
			list: [],
			yearList:[],
			count: 0,
			loadStatus: 'loadmore',
			options: [
				{text: '删除', style: { background: '#dd524d'}}
			]
		};
	},
	onLoad() {
		this.query.taskYear = new Date().getFullYear();
		this.loadList();
	},
	onShow() {
		if (uni.getStorageSync('refreshList') === true){
			uni.removeStorageSync('refreshList');
			this.search('');
		}
	},
	onReady(){
		this.$u.api.taskInfo.getYear().then(res => {
					res.data.map(item => {
						this.yearList.push({
							name: item.dictLabel,
							value: item.dictValue
						});
					});
				});
	},
	methods: {
		getYear1(val) {
					this.model.taskYear = val[0];
				},
		resetAll() {
			this.query.pageNo = 1;
			this.query.taskTitle = '';
			this.query.taskYear = new Date().getFullYear();
			this.query.taskStatus=1
			this.query.remarks=1
			this.list = [];
			this.loadList();
		},
		doQuery() {
			this.list = [];
			this.query.pageNo = 1;

			this.loadList();
		},
		getStatusType(val) {
			this.query.remarks = val[0];
			if(val[0]==1){
				this.query.taskStatus = val[0];
				this.query.transferFlag=''
			}else if(val[0]==4){
				this.query.taskStatus=''
				this.query.transferFlag=1
			}else{
				this.query.taskStatus=''
				this.query.transferFlag=''
			}
			this.query.taskStatusName = val[1];
		},
		loadMore() {
			this.loadStatus = "loading";
			setTimeout(() => {
				this.query.pageNo += 1;
				this.loadList();
			}, 100);
		},
		loadList() {
			this.$u.api.taskReceive.list(this.query).then(res => {
				if (!res.list || res.list.length == 0){
					this.loadStatus = "nomore";
					return;
				}
				this.list = this.list.concat(res.list);
				this.count = res.count;
				this.query.pageNo = res.pageNo;
				this.query.pageSize = res.pageSize;
				this.loadStatus = "loadmore";
			});
		},
		optionsClick(rowIndex, btnIndex) {
			if(btnIndex == 0) {
				let self = this;
				uni.showModal({
					title: '提示',
					content: '确认要删除该数据吗？',
					showCancel: true,
					success: function (res2) {
						if (res2.confirm) {
							let row = self.list[rowIndex];
							self.$u.api.testData.delete({id: row.id}).then(res => {
								self.$u.toast(res.message);
								if (res.result == 'true'){
									self.list.splice(rowIndex, 1);
								}
							});
						}
					}
				});
			}
		},
		search(value) {
			this.query.taskTitle=value
			this.list = [];
			this.query.pageNo = 0;
			// this.query.testInput = value;
			this.loadList();
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>
<style lang="scss">
page {
	background-color: #f8f8f8;
}
.btn-plus {
	position: absolute;
	bottom: 50rpx;
	right: 50rpx;
	z-index: 1;
	opacity: 0.6;
}
.btn-plus:hover {
	opacity: 1;
}
.uni-flex {
	display: flex;
	flex-direction: row;
}
</style>
